﻿

#region Using

using System;
using System.ComponentModel;
using System.Custom.Generic;
using System.Drawing;
using System.Runtime.CompilerServices;
using CoCoon.Forms.Ribbon;
using Gizmox.WebGUI;
using Gizmox.WebGUI.Common.Interfaces;
using Gizmox.WebGUI.Forms;
using Gizmox.WebGUI.Forms.Skins;

#endregion Using

namespace CoCoon.Forms
{
    /// <summary>
    ///     A button control
    /// </summary>
    [Skin(typeof(RibbonBarPushButtonSkin))]
    public class PushButton : Button
    {
        public PushButton()
        {
        }

        protected override void RenderAttributes(IContext objContext, IAttributeWriter objWriter)
        {
            base.RenderAttributes(objContext, objWriter);
            objWriter.WriteAttributeString("MyIsPushed", Pushed ? "1" : "0");
            //objWriter.WriteAttributeString("MyIsPushed", "1");
        }

        private bool _pushed;
        
        [DefaultValue(false)]
        public bool Pushed
        {
            get { return _pushed; }
            set
            {
                if (value.Equals(_pushed)) return;
                _pushed = value;
//                OnPushedChanged();
                Update();
            }
        }

        //protected override void FireEvent(IEvent objEvent)
        //{
        //    if (objEvent.Type == "Click")
        //    {
        //        Pushed = !Pushed;
        //    }            
        //    base.FireEvent(objEvent);

        //}

        public event EventHandler<EventArgs<bool>> PushedChanged;

        protected virtual void OnPushedChanged()
        {
            var handler = PushedChanged;
            if (handler != null) handler(this, new EventArgs<bool>(Pushed));
        }
    }
}